<?php

namespace search\controllers\bigdata;

use business\elasticsearch\services\BigDataCommencePermitService;

class CommencePermitController extends BaseController
{
    public $enableCsrfValidation = false;//csrf安全
    /**
     * @api {get} /bigdata/developer/get-list 01、大数据开工搜索
     *
     * @apiVersion 1.0.0
     * @apiGroup bigdataCommencePermit
     *
     * @apiDescription 01、大数据开工搜索
     *
     * @apiParam {String} keyword                           搜索词
     * @apiParam {String} province                          省份
     * @apiParam {String} city                              城市
     * @apiParam {String} company_type                      企业类型
     * @apiParam {String} area_lower                        面积L
     * @apiParam {String} area_upper                        面积U
     * @apiParam {String} price_lower                       价格L
     * @apiParam {String} price_upper                       价格U
     * @apiParam {String} start_lower                       开工日期L
     * @apiParam {String} start_upper                       开工日期U
     * @apiParam {String} finish_lower                      竣工日期L
     * @apiParam {String} finish_upper                      竣工日期U
     * @apiParam {String} page                              页码
     * @apiParam {String} pageSize                          分页size
     *
     * @apiSuccess {Boolean} success                    返回状态
     * @apiSuccess {String}  message                    返回消息内容
     * @apiSuccess {Number}  errorCode                  错误码
     * @apiSuccess {Object}  data                       对象数组
     * 
     */
    public function actionGetList()
    {
        try {
            $keyword        = $this->getParam('keyword');
            $province       = $this->getParam('province');
            $city           = $this->getParam('city');
            $companyType    = $this->getParam('company_type');
            $areaLower      = $this->getParam('area_lower');
            $areaUpper      = $this->getParam('area_upper');
            $priceLower     = $this->getParam('price_lower');
            $priceUpper     = $this->getParam('price_upper');
            $beginLower     = $this->getParam('begin_lower');
            $beginUpper     = $this->getParam('begin_upper');
            $finishLower    = $this->getParam('finish_lower');
            $finishUpper    = $this->getParam('finish_upper');
            $page           = $this->getParam('page');
            $pageSize       = $this->getParam('page_size');
            $page           = intval($page) > 0 ? intval($page) : 1;
            $pageSize       = intval($pageSize) > 0 ? intval($pageSize) : 10;
            if (!empty($province)) {
                $province= explode(",",$province);
            }else{
                $province=[];
            }

            $bigDataDeveloperService = new BigDataCommencePermitService();
            $rs                      = $bigDataDeveloperService->getDataList($keyword, $province, $city, $companyType, 
                $areaLower, $areaUpper, $priceLower, $priceUpper, 
                $beginLower, $beginUpper, $finishLower, $finishUpper, $page, $pageSize);
            return $this->success($rs);
        } catch (\Exception $ex) {
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }

        /**
     * @api {get} /bigdata/purchase/guess-names 02、开工联想
     *
     * @apiVersion 1.0.0
     * @apiGroup bigdataCommencePermit
     *
     * @apiDescription 02、开工联想
     *
     * @apiParam {String} keyword                   搜索词
     * @apiParam {String} pageSize                  分页size
     *
     * @apiSuccess {Boolean} success                    返回状态
     * @apiSuccess {String}  message                    返回消息内容
     * @apiSuccess {Number}  errorCode                  错误码
     * @apiSuccess {Object}  data                       对象数组
     * @apiSuccess {Object}  data.total
     * @apiSuccess {Object}  data.list
     * @apiSuccess {Number}  data.list.titleHL     搜索词高亮开工项目名
     * @apiSuccess {String}  data.list.title       开工项目
     *
     *
     */
    public function actionGuessNames()
    {
        try {
            $keyword  = $this->getParam('keyword');
            $pageSize = $this->getParam('page_size');
            $pageSize = intval($pageSize) > 0 ? intval($pageSize) : 10;

            if (empty($keyword)) {
                throw new \Exception('你的关键字没有传');
            }
            $bigDataPurchaseService = new BigDataCommencePermitService();
            $rs                     = $bigDataPurchaseService->guessNames($keyword, $pageSize);
            return $this->success($rs);

        } catch (\Exception $ex) {
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }
}